package com.cn.reflection;

import cn.hutool.core.collection.CollectionUtil;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.log4j.Log4j;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author he_ls
 * @since 2024/8/15 15:02
 **/
@Accessors(chain = true, prefix = "hah")
public class MyReflection {
    public Integer id;
    protected String name;
    Integer age;
    private String birthday;
    public static final Boolean BOOL_NAME = true;

    public MyReflection() {
        System.out.println("无参构造");
    }

    private MyReflection(Integer id, String name) {
        this.id = id;
        this.name = name;
        System.out.println("2个参数构造");
    }

    public MyReflection(Integer id, String name, Integer age, String birthday) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.birthday = birthday;
        System.out.println("全参数构造");
    }

    @Override
    public String toString() {
        return "MyReflection{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", birthday='" + birthday + '\'' +
                '}';
    }

    public String draw(String str) {
        id = 0;
        name = "小明";
        List<String> list = CollectionUtil.toList("xx", "ddd", null,"gg", "ss");
        List<String> sList = list.stream()
                .filter(Objects::nonNull)
                .filter(dto -> dto.equals("ss"))
                .map(String::valueOf)
                .collect(Collectors.toList());
        System.out.println("画画" + str);
        return str;
    }

    void eat() {
        System.out.println(this.id + this.name);
        System.out.println("吃吃");
        TestReflection tr = new TestReflection();
        tr.test();
        return;
    }

    public static void main(String[] args) {
        Class<?> c1 = null;
        try {
            c1 = Class.forName("com.fawkes.ytcim.modules.aa.MyReflection");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        Class<MyReflection> c2 = MyReflection.class;
        MyReflection obj = new MyReflection();
        Class<? extends MyReflection> c3 = obj.getClass();
        try {
            Object o1 = c1.newInstance();
            MyReflection o2 = c2.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }

        Constructor<?>[] constructors = c1.getDeclaredConstructors();
        for (Constructor con : constructors) {
            System.out.println(con);
        }


    }


}
